package com.fenghongzhang.login.util;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpUtil {

    private HttpUtil() {
    }
    private static HttpUtil httpUtil = null;
    public synchronized static HttpUtil getHttpUtil() {
        if(httpUtil == null){
            httpUtil = new HttpUtil();
        }
        return httpUtil;
    }
    private Retrofit retrofit;
    public synchronized Retrofit getRetrofit(){
        if(retrofit ==null){
            retrofit = new Retrofit.Builder()
                    .baseUrl("http://49.233.0.68:8080/")
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(new OkHttpClient.Builder().addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build())
                    .build();
        }
        return retrofit;
    }
}
